﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Calc
{
    class myCalc
    {
        private double first;
        private double second;
        private char action;
        private double memory;
        private bool bMemory;
        
        public myCalc() { first = second = 0; action = '0'; bMemory = false; }
        
        public void reset() { first = second = 0; action = '0'; }
        
        public void setFirst(double d)
        { first = d; }
        
        public void setSecond(double d)
        { second = d; }
        
        public void setAction(char c)
        {
            if (c != '-' && c != '+' && c != '*' && c != '/')
            {
                throw new Exception("Uncorrect action");
            }
            action = c;
        }
        
        public string countUp()
        {
            switch (action)
            {
                case '-':
                    {
                        first -= second;
                        break;
                    }
                case '+':
                    {
                        first += second;
                        break;
                    }
                case '*':
                    {
                        first *= second;
                        break;
                    }
                case '/':
                    {                        
                        first /= second;
                        break;
                    }
            }
            return first.ToString();
        }
        
        public void memoryClear()
        { bMemory = false; }
        
        public string memoryReload()
        { return memory.ToString(); }
        
        public void memorySave(double d)
        {
            bMemory = true;
            memory = d;
        }
        
        public void memoryPlus(double d)
        {
            if (!bMemory)
            {
                memory = 0;
                bMemory = true;
            }
            memory += d;
        }
        
        public void memoryMines(double d)
        {
            if (!bMemory)
            {
                memory = 0;
                bMemory = true;
            }
            memory -= d;
        }
        
        public string sqrt()
        {
            first = Math.Sqrt(first);
            return first.ToString(); 
        }        
        
        public string reciproc()
        {
            first = 1 / first;
            return first.ToString(); 
        }
    }
}
